home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / INFINITE.MOD < prev    next >
Text File  |  1989-01-18  |  2KB  |  69 lines

  1.                                      (* Chapter 15 - Program 5 *)
  2. MODULE Infinite;                    (* Infinite Coroutine loop *)
  3.  
  4. FROM InOut IMPORT WriteCard, WriteString, WriteLn;
  5.  
  6. FROM SYSTEM IMPORT WORD, PROCESS, ADR, SIZE,
  7.                    NEWPROCESS, TRANSFER;
  8.  
  9. VAR  main, Process1, Process2 ,Process3 : PROCESS;
  10.      WorkSpace1, WorkSpace2, WorkSpace3 : ARRAY[1..300] OF WORD;
  11.      Index : CARDINAL;
  12.  
  13. PROCEDURE MainProcess;
  14. BEGIN
  15.    LOOP
  16.       WriteString('Main Process');
  17.       (* This may check the printer and send another character  *)
  18.       (* for printing if it is ready.                           *)
  19.       TRANSFER(Process1,Process2);
  20.       WriteLn;
  21.    END;
  22. END MainProcess;
  23.  
  24. PROCEDURE SubProcess;
  25. BEGIN
  26.    LOOP
  27.       WriteString(' SubProcess');
  28.       (* This may check to see if there are any additional      *)
  29.       (* characters to be read from the keyboard.               *)
  30.       TRANSFER(Process2,Process3);
  31.    END;
  32. END SubProcess;
  33.  
  34. PROCEDURE ThirdProcess;
  35. BEGIN
  36.    LOOP
  37.       WriteString(' ThirdProcess');
  38.       (* This may check to see if there was another update in    *)
  39.       (* the clock requiring service by the system.              *)
  40.       TRANSFER(Process3,Process1);
  41.    END;
  42. END ThirdProcess;
  43.  
  44. BEGIN   (* Main Module Body *)
  45.    NEWPROCESS(MainProcess,ADR(WorkSpace1),SIZE(WorkSpace1),
  46.               Process1);
  47.    NEWPROCESS(SubProcess,ADR(WorkSpace2),SIZE(WorkSpace2),
  48.               Process2);
  49.    NEWPROCESS(ThirdProcess, ADR(WorkSpace3),SIZE(WorkSpace3),
  50.               Process3);
  51.    TRANSFER(main,Process1);
  52.    (* Note that we never return here, we stay in the status loop *)
  53. END Infinite.
  54.  
  55.  
  56.  
  57.  
  58. (* Result of execution
  59.  
  60. Main Process SubProcess ThirdProcess
  61. Main Process SubProcess ThirdProcess
  62. Main Process SubProcess ThirdProcess
  63. Main Process SubProcess ThirdProcess
  64. Main Process SubProcess ThirdProcess
  65.  (The above repeats indefinitely)
  66.  
  67. *)
  68.  
  69.